/*
 * @Autor: dingxiaolin
 * @Date: 2020-05-28 22:48:51
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2020-06-13 17:02:32
 */

// 这个文件只是用于解释react-loadable原理用。当然可以无缝切换
import React, { Component } from "react";
import { Loading } from "components";

const Loadable = ({ loader, loading: Loading }) => {
  return class LoadableComponent extends Component {
    state = {
      LoadedComponent: null,
    };
    componentDidMount() {
      // import('./Dashboard')
      loader().then((resp) => {
        this.setState({
          LoadedComponent: resp.default,
        });
      });
    }
    render() {
      const { LoadedComponent } = this.state;
      return LoadedComponent ? <LoadedComponent /> : <Loading />;
    }
  };
};
export default Loadable;
